//
//  HHTabBar.m
//  oschina
//
//  Created by hjl on 16/3/30.
//  Copyright © 2016年 hjl. All rights reserved.
//

#import "HHTabBar.h"

@implementation HHTabBar

// 创建加号按钮
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        UIButton *plusBtn = [[UIButton alloc]init];

        [plusBtn setBackgroundColor:HHBackgroundColor];
        [plusBtn setImage:[UIImage imageNamed:@"tabbar-more"] forState:UIControlStateNormal];
        
        
        [plusBtn addTarget:self action:@selector(plusBtnClick) forControlEvents:UIControlEventTouchUpInside];
        
        [self addSubview:plusBtn];
    }
    return self;
}

- (void)plusBtnClick{

}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    CGFloat childX = 0;
    CGFloat childY = 0;
    CGFloat childH = self.height;
    CGFloat childW = HHWidth / 5;
    NSInteger index = 0;
    
    for (UIView *child in self.subviews) {
        if ([child isKindOfClass:[UIControl class]]) {
            if ([child isKindOfClass:[UIButton class]]) {
                childX = 2 * childW;
                child.frame = CGRectMake(childX + 7, childY + 5, childW - 14, childH - 10);
            }
            else{
                if (index == 2) {
                    index ++;
                }
                childX = index * childW;
                child.frame = CGRectMake(childX, childY, childW, childH);
                index ++;
            }
        }
    }
}

@end
